/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = jboss_get_string.c                          */
/*  NOTE      =                                                    */
/*  DATE      = 2015/11/19 by geyh                                 */
/*******************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>

#include <jbossmq/jbossmq_comm.h>
#include <jbossmq/jbossmq_core.h>
#include "frcomm.h"
#include "frmem.h"
#include "conntrack.h"
#include "frct_comm.h"
#include "frbyte_buffer.h"
#include "frlist.h"
#include "frreport_comm.h"
#include "apmtest_cunit.h"
#include "apmtest_comm.h"

#include "../../../src/module/jbossmq/config.h"

extern int jboss_get_string(Frbyte_Packet *p_st_data, char **pp_simple_str, int i_flag_need);

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}

static void __case1(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    char *p_out = NULL;

    p_st_data = bytebuff_creat();

    bytebuff_add(p_st_data, (char *)"\x00\x00\x00\x02\x65\x00", 6);

    i_ret = jboss_get_string(p_st_data, &p_out, 1);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_STRING_EQUAL(p_out, (char *)"e");

    bytebuff_free(&p_st_data);
    frfree(p_out);

    return;
}


static void __case2(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    char *p_out = NULL;

    p_st_data = bytebuff_creat();

    bytebuff_add(p_st_data, (char *)"\x00\x00\x00\x04\x65\x00", 6);

    i_ret = jboss_get_string(p_st_data, &p_out, 1);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);

    bytebuff_free(&p_st_data);

    return;
}

static void __case3(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    char *p_out = NULL;

    p_st_data = bytebuff_creat();

    bytebuff_add(p_st_data, (char *)"\x00\x00\x00\x02\x65\x00", 6);

    i_ret = jboss_get_string(p_st_data, &p_out, 0);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_PTR_NULL(p_out);

    bytebuff_free(&p_st_data);

    return;
}


int add_suite_jboss_get_string(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" jboss_get_string()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", __case1);
    CU_add_test(pSuite, "case2", __case2);
    CU_add_test(pSuite, "case3", __case3);


    return FR_SUCC;

}
